#pragma once
/*
*
*
*/
/**
* @file Joint.h
* @brief 
* @date 1/2/2011
* @author Jing HUANG
*/

#include <string>
#include <vector>
#include <map>
#include "../../math/Vectors.h"
#include "../../math/Quaternion.h"

namespace Etoile
{
	class Skeleton;
	class Joint
	{
	public:
		Joint(const std::string& name, Skeleton* skeleton, int id = -1 , int parentId = -1);

		std::string getName(){return _name;}
		void setName(const std::string& name){ _name = name;}
		int getId(){ return _id;}
		void setId(int id){ _id = id;}
		void setParent(int parent){ _parent = parent;}
		int getParentId(){return _parent;}
		Joint* getParent()const;
		Skeleton* getSkeleton() const;
		void setSkeleton(Skeleton*);

		bool addChild(int id);
		bool addChild(Joint* joint);
		Joint* getChild(unsigned int index);
		bool removeChild(unsigned int index);
		std::vector<int>& getChildren()
		{
			return _children;
		}

		
		void rotate(const Quaternion& rotation);
		void updateLocally();
		virtual void update();
		void reset();

		void setOriginalLocalPosition(const Vec3d& pos);
		Vec3d getOriginalLocalPosition(){return _originalLocalPosition;}
		double getLength();

		void setLocalRotation(const Quaternion& local);
		Quaternion getLocalRotation();

		//void setWorldRotation(const Quaternion& world);
		Quaternion getWorldRotation();

		void setLocalPosition(const Vec3d& pos);
		const Vec3d& getLocalPosition();

		//void setWorldPosition(const Vec3d& pos);
		const Vec3d& getWorldPosition();


	protected:
		Skeleton* _pSkeleton;
		std::string _name;
		int _id;
		int _parent;
		std::vector<int> _children;

		double _length;
		Vec3d _originalLocalPosition;

		Quaternion _localRotation;
		Quaternion _worldRotation;
		Vec3d _localPosition;
		Vec3d _worldPosition;
	};

	typedef std::vector<Joint*> Joints;

}
